var ym = {};
/**
 * ios回退加载
 * @param event
 */
window.onpageshow = function(event) {
    if (event.persisted) {
        window.location.reload();
    }
};

ym.perSex=0;
ym.schoolId="a";
ym.slfToken="slfToken";
//Cookie名称
/**
 * 设置Cookie 有效时间30天
 */
ym.setCookie = function(k,v){
    $.cookie(k,v,{expiress:31});
}
/**
 * 过去Cookie值
 */
ym.getCookie = function(k){
    return $.cookie(k);
}

/**
 * 用户对象
 */
ym.user = {};

ym.defau = {};

ym.childList={};
/**
 * 判断是否为空
 */
ym.isBlank = function(value) {
    if (value == undefined) {
        return true;
    }
    if (value == null) {
        return true;
    }
    if (value == "") {
        return true;
    }
    return false;
}

/**
 * 重写ajax 请求
 */
ym.ajax = function() {
    $("#my-modal-loading").modal('open');
    var operate = arguments[0] || {};
    var url =operate.url || "";
    var async = typeof (operate.async) == 'boolean' ? operate.async : true;
    var param = operate.param || {};
    var dataType = operate.dataType || "jsonp";
    var type = operate.type || "GET";
    var contentType = operate.contentType || "application/x-www-form-urlencoded; charset=utf-8";
    var loading = operate.loading || '正在处理中...';
    var success = operate.success || function(data) {};
    var beforeSend = operate.beforeSend || function(data) {};
    var complete = operate.complete || function(data) {};
    var error = operate.error || function(data) {};
    param.token = ym.getCookie(ym.slfToken);
    if (!ym.isBlank(url)) {
        url="http://111.230.17.122:8083"+url;
        //url="http://192.168.0.113:80/wachat"+url;
        $.ajax({
            type : type,
            url : url,
            contentType : contentType,
            // dataType : dataType,
            data :param,
            beforeSend : function(data){
                beforeSend(data);
            },
            error : function(data){
                error(data);
            },
            complete : function(data) {
                complete(data);
            },
            success : function(data) {
                var url = window.location.href;
                var index = url .lastIndexOf("\/");
                url  = url .substring(index + 1, url .length);
                if(url=="index.html"||url=="course_pack.html"){
                    setTimeout(function(){
                        $('#my-modal-loading').modal('close');
                    },3000);
                }else{
                    $("#my-modal-loading").modal('close');
                }
                if(data){
                    if(data.res == "234"){
                        alert(data.resMsg);
                        window.location.href = "/ym/login.html"
                    }else{
                        success(data);
                    }
                }
            }
        });
    }
}

/**
 * 获取用户信息
 */
function getUser(){
    $.ajax({
        url : "/web/user/getTestUser",
        async : false,
        success : function(data){
            ym.user=data.obj;
        }
    });
}
/**
 * 获取url参数
 */
ym.getQueryStringByName = function(name) {
    var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
    if (result == null || result.length < 1) {
        return "";
    }
    return decodeURI(result[1]);
}
